package com.taxinfo.controller;

import com.taxinfo.component.alert.MyAlert;
import com.taxinfo.pojo.dto.MainReportDto;
import com.taxinfo.pojo.dto.StandardSubDto;
import com.taxinfo.service.StandardSubService;
import com.taxinfo.utils.SpringUtil;
import com.taxinfo.view.dataImport.DataImportTable;
import com.taxinfo.view.standard.StandardSubTable;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;

import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;

public class StandardSubController implements Initializable {

    private final StandardSubService standardSubService  = (StandardSubService) SpringUtil.getBean("StandardSubServiceImpl");

    @FXML
    public TextField subName;
    @FXML
    public ComboBox category;
    @FXML
    public ScrollPane scrollPane;

    private StandardSubTable table;

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        List<StandardSubDto> dtoList = standardSubService.selectAllData("","");
        table = new StandardSubTable(dtoList);
        scrollPane.setContent(table);
        category.getItems().addAll("全部","余额表科目","负债表科目","利润表科目");
        category.setValue("全部");
    }

    @FXML
    private void findInfo() {
        String sCondition = "";
        if (category.getValue().equals("全部")) {
            sCondition = "";
        }else{
            sCondition =String.valueOf(category.getValue());
        }
        List<StandardSubDto> dtoList = standardSubService.selectAllData(subName.getText(),sCondition);
        if (dtoList != null) {
            table.clearData();
            for (StandardSubDto bean : dtoList)
                table.addBean(bean);
        } else {
            new MyAlert(Alert.AlertType.INFORMATION, "没有找到您查找的标准科目信息！").show();
        }
    }
}
